package cn.tedu.collection;/**
 * @Author 金帮嘉诚 @Date 2021-06-23 星期三 21:01
 */
/*本类用于测试Set接口*/

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**知识点
 * Set
 * 无序   不可重复   可存放null一个
 * Set只有Collection接口中的方法
 * 只是不可重复
 * HashSet底层是HashMap
 * */
public class TestSet {
    public static void main(String[] args) {
        Set<String > set = new HashSet<>();
        set.add("金帮嘉诚");
        set.add("是大帅逼");
        set.add("我喜欢你");
        set.add("永远永远");
        set.add("金帮嘉诚");

        System.out.println("set = " + set);
        System.out.println("set.contains(\"金帮嘉诚\") = " + set.contains("金帮嘉诚"));

        System.out.println("set.hashCode() = " + set.hashCode());
        System.out.println("set.isEmpty() = " + set.isEmpty());
        System.out.println("set.size() = " + set.size());

        System.out.println("set.equals(\"金帮嘉诚\") = " + set.equals("金帮嘉诚"));
        Object[] obj=set.toArray();
        System.out.println("obj = " + obj);
        String s = Arrays.toString(obj);
        System.out.println("Arrays.toString(set.toArray)" + s);

        //addAll containAll removeAll
        Set<String > set1=new HashSet<>();
        set1.add("水野朝阳");
        set1.add("是大美女");
        set1.add("我喜欢你");
        set1.add("永远永远");
        System.out.println("set.addAll(set1) = " + set.addAll(set1));
        System.out.println("set = " + set);

        System.out.println("set.containsAll(set1) = " + set.containsAll(set1));
        System.out.println("set.retainAll(set1) = " + set.retainAll(set1));
        System.out.println("set = " + set);

        System.out.println("set.removeAll(set1) = " + set.removeAll(set1));
    }
}
